package com.lkx.web;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lkx.domain.ApiSubject;
import com.lkx.domain.ApiType;
import com.lkx.domain.User;
import com.lkx.service.ApiTypeService;
import com.lkx.util.PageModule;

@Controller
@RequestMapping("back/apiType")
@ResponseBody
public class BackApiTypeController {

    @Autowired
    private ApiTypeService apiTypeService;

    @RequestMapping("list")
    public PageModule list(HttpSession session, Long subjectId) {
        User user = (User) session.getAttribute("user");
        PageModule module = apiTypeService.list(subjectId, user.getId());
        return module;
    }

    @RequestMapping("add")
    public PageModule add(HttpSession session, Long subjectId, String apiType) {
        PageModule module = new PageModule();
        User user = (User) session.getAttribute("user");
        ApiType model = new ApiType();
        model.setUserId(user.getId());
        model.setSubjectId(subjectId);
        model.setApiType(apiType);
        int num = apiTypeService.add(model);
        if (num > 0) {
            module.setStatus(true);
            module.setObject(model.getId());
        }
        return module;
    }

}
